package com.lagou.mr.sortnumber;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class OrderLong implements WritableComparable<OrderLong> {
    private Long order;
    private Long number;

    public OrderLong() {
    }

    public OrderLong(Long order, Long number) {
        this.order = order;
        this.number = number;
    }

    @Override
    public int compareTo(OrderLong o) {
        if (this.number > o.number) {
            return -1;
        } else if (this.number < o.number) {
            return 1;
        } else {
            return 0;
        }
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(order);
        out.writeLong(number);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.order = in.readLong();
        this.number = in.readLong();
    }

    public Long getOrder() {
        return order;
    }

    public void setOrder(Long order) {
        this.order = order;
    }

    public Long getNumber() {
        return number;
    }

    public void setNumber(Long number) {
        this.number = number;
    }

    @Override
    public String toString() {
        return order + "\t" + number;
    }
}
